package com.example.lwj.zhangtianchengnews;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.example.lwj.BaseDemo.BaseDate;
import com.example.lwj.BeanDemo.NewsTitleRoot;
import com.example.lwj.utils.CommonUtls;
import com.example.lwj.utils.URLUtils;
import com.google.gson.Gson;

public class LaunchActivity extends AppCompatActivity {
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Intent intent=new Intent(LaunchActivity.this,MainActivity.class);
            startActivity(intent);
            finish();
            handler.removeCallbacksAndMessages(null);
        }
    };
    private StringBuilder stringBuilder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launch);
        //3秒钟跳过
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
        handler.sendEmptyMessageDelayed(0,5000);
=======
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
        handler.sendEmptyMessageDelayed(0,5000);
=======
        handler.sendEmptyMessageDelayed(0,3000);
>>>>>>> name
>>>>>>> name
         //请求拿到标题
        BaseDate baseDate=new BaseDate() {

            @Override
            protected void setFailResult(int error_Net) {

            }

            @Override
            public void setResultData(String data) {
                //解析拿到数据
                Gson gson=new Gson();
                NewsTitleRoot bean = gson.fromJson(data, NewsTitleRoot.class);
                // 热点：news—hot，天气：news-WEATHER
                stringBuilder = new StringBuilder();
                stringBuilder.append("推荐:,");
                for (int i = 0; i <bean.getData().getData().size() ; i++) {
                    NewsTitleRoot.DataBean.MyDataBean myDataBean = bean.getData().getData().get(i);
                    String name = myDataBean.getName();
                    String category = myDataBean.getCategory();
                    stringBuilder.append(name + ":" + category + ",");
                }
                CommonUtls.getsp("newsTitle",stringBuilder.toString());
            }
        };
        baseDate.getData(URLUtils.URL_TITLE_PATH, BaseDate.LONGTIME);

    BaseDate baseDate1=new BaseDate() {
        @Override
        public void setResultData(String data) {

        }

        @Override
        protected void setFailResult(int error_Net) {

        }
    };
    baseDate1.getData(URLUtils.URL_CATEGROY_PATH+"news_hot ",BaseDate.LONGTIME);
        BaseDate baseData2=new BaseDate() {
            @Override
            public void setResultData(String data) {

            }

            @Override
            protected void setFailResult(int error_Net) {

            }
        };
        baseData2.getData(URLUtils.URL_CATEGROY_PATH,BaseDate.LONGTIME);
    }

}
